<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增订单')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-order-add">
            <h4 class="form-header h4">[[#{order}]]</h4>
            <div class="rows">
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">[[#{orderNo}]]：</label>
                    <div class="col-sm-8">
                        <input name="orderNo" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">[[#{buyerRemark}]]：</label>
                    <div class="col-sm-8">
                        <textarea name="buyerRemark" class="form-control" rows="3"></textarea>
                    </div>
                </div>
            </div>
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">[[#{sellerRemark}]]：</label>
                    <div class="col-sm-8">
                        <textarea name="sellerRemark" class="form-control" rows="3"></textarea>
                    </div>
                </div>

            </div>
            <h4 class="form-header h4">[[#{logisticsInformation}]]</h4>
            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">[[#{logisticsCompany}]]：</label>
                        <div class="col-sm-8">
                            <input name="logisticsCompany" class="form-control" type="text">
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">[[#{trackingNo}]]：</label>
                        <div class="col-sm-8">
                            <input name="trackingNumber" class="form-control" type="text">
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">[[#{currency}]]：</label>
                        <div class="col-sm-8">
                            <input name="currency" class="form-control" type="text">
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">[[#{shippingFee}]]：</label>
                        <div class="col-sm-8">
                            <input name="freightAmount" class="form-control" type="number">
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">[[#{discounts}]]：</label>
                        <div class="col-sm-8">
                            <input name="reduceAmount" class="form-control" type="number">
                        </div>
                    </div>
                </div>
            </div>
            <h4 class="form-header h4">[[#{deliveryInformation}]]</h4>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">[[#{Receiver}]]：</label>
                    <div class="col-sm-8">
                        <input name="receiver" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">[[#{contactNumber}]]：</label>
                    <div class="col-sm-8">
                        <input name="phoneNumber" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">[[#{region}]]：</label>
                    <div class="col-sm-8">
                        <input name="country" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">[[#{province}]]：</label>
                    <div class="col-sm-8">
                        <input name="province" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">[[#{city}]]：</label>
                    <div class="col-sm-8">
                        <input name="city" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">[[#{detailedAddress}]]：</label>
                    <div class="col-sm-8">
                        <input name="fullAddress" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">[[#{zipCode}]]：</label>
                    <div class="col-sm-8">
                        <input name="zipCode" class="form-control" type="text">
                    </div>
                </div>
            </div>

            <h4 class="form-header h4" th:text="#{productInfo}">订单明细信息</h4>
            <div class="row">
                <div class="col-xs-12">
                    <button type="button" class="btn btn-white btn-sm" onclick="addRow()"><i class="fa fa-plus"> [[#{add}]]</i></button>
                    <button type="button" class="btn btn-white btn-sm" onclick="sub.delRow()"><i class="fa fa-minus"> [[#{delete}]]</i></button>
                    <div class="col-sm-12 select-table table-striped">
                        <table id="bootstrap-table"></table>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "business/order"
        $("#form-order-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-order-add').serialize());
            }
        }

        $(function() {
            var options = {
                pagination: false,
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                sidePagination: "client",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'index',
                    align: 'center',
                    title: i18n('serialNumber'),
                    formatter: function (value, row, index) {
                    	var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                    	return columnIndex + $.table.serialNumber(index);
                    }
                },
                {
                    field: 'productId',
                    align: 'center',
                    title: '产品ID',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='jtOrderItemList[%s].productId' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'skuId',
                    align: 'center',
                    title: 'SKU ID',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='jtOrderItemList[%s].skuId' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'prodName',
                    align: 'center',
                    title: '产品名称',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='jtOrderItemList[%s].prodName' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'skuName',
                    align: 'center',
                    title: 'sku名称',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='jtOrderItemList[%s].skuName' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'price',
                    align: 'center',
                    title: '价格',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='jtOrderItemList[%s].price' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'prodCount',
                    align: 'center',
                    title: '数量',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='jtOrderItemList[%s].prodCount' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'totalAmount',
                    align: 'center',
                    title: '总金额',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='jtOrderItemList[%s].totalAmount' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var value = $.common.isNotEmpty(row.index) ? row.index : $.table.serialNumber(index);
                        return '<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="sub.delRowByIndex(\'' + value + '\')"><i class="fa fa-remove"></i>删除</a>';
                    }
                }]
            };
            $.table.init(options);
        });

        function addRow() {
            var count = $("#" + table.options.id).bootstrapTable('getData').length;
            var row = {
                index: $.table.serialNumber(count),
                productId: "",
                skuId: "",
                prodName: "",
                skuName: "",
                price: "",
                prodCount: "",
                totalAmount: ""
            }
            sub.addRow(row);
        }


        function selectProduct() {

        }
    </script>
</body>
</html>